#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <pthread.h>

#include "uri.h"
#include "socket.h"
#include "http.h"
#include "progress.h"

int main(int argc, char **argv) {

   URI *uri;

   if(strstr(argv[1], "http://") != NULL) {

      uri = http_get_header(argv[1]);

      download(uri);













/*
      if( (sock = connect_http(uri)) != NULL) {

         percent = (int) uri->lenght / 100;
         uri->progress=0;
         //uri->time_last = (int) time(NULL);
         uri->bytes=1;

         fp = fopen(uri->file, "w");
         printf("\n");
         
         pthread_create(&tid, NULL, update_progress, (void *)uri);

         while(feof(fp) == 0 && uri->lenght >= uri->bytes) {
            fread(buffer, 1, 1 , sock->f);

            fwrite(buffer, 1, 1, fp);
            if(uri->bytes % percent == 0) show_progress(uri);

            uri->bytes++;
         }

         fclose(fp);
         printf("\n");

         fclose(sock->f);
         close(sock->fd);
      }
*/
   } else {

      printf("The protocol '%s' isn't supported\n", uri->protocol);
      exit(0);

   }

   return 0;

}
